package com.farm.wcp.DO;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.farm.wcp.pojo.FileInformation;

@Repository
public class FileInformationDo {
	@Resource
	private SessionFactory sessionFactory;
	public boolean save( FileInformation fileInformation){
		Boolean b=false;
		Session session=sessionFactory.getCurrentSession();
		session.save(fileInformation);
		b=true;
		return b;
	}
	//总查询
	public List<FileInformation>  select(){
		Session session=sessionFactory.getCurrentSession();
		return	session.createQuery("from FileInformation").list();
	}
	//分类总查询
		public List<FileInformation>  select(int type){
			Session session=sessionFactory.getCurrentSession();
			return	session.createQuery("from FileInformation where type="+type).list();
		}
	//分页查询
	public List<FileInformation>  select(int size,int page){
		Session session=sessionFactory.getCurrentSession();
		Query query=	session.createQuery(" from FileInformation ");
		query.setFirstResult((page-1)*size);
		query.setMaxResults(size);
		return 	query.list();
	}
	//分类分页查询
		public List<FileInformation>  select(int size,int page,int type){
			Session session=sessionFactory.getCurrentSession();
			Query query=	session.createQuery(" from FileInformation where type="+type);		
			query.setFirstResult((page-1)*size);
			query.setMaxResults(size);
			return 	query.list();
		}


}
